/*   1:    */ package org.jetbrains.debugger.sourcemap;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.editor.Document;
import com.intellij.util.Processor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */ 
/*  11:    */ public abstract class MappingList
/*  12:    */ {
/*  13:    */   private final List<MappingEntry> a;
/*  14:    */   
/*  15:    */   public MappingList(@NotNull List<MappingEntry> paramList)
/*  16:    */   {
/*  17: 16 */     this.a = paramList;
/*  18:    */   }
/*  19:    */   
/*  20:    */   public int getSize()
/*  21:    */   {
/*  22: 20 */     return this.a.size();
/*  23:    */   }
/*  24:    */   
/*  25:    */   protected abstract Comparator<MappingEntry> getComparator();
/*  26:    */   
/*  27:    */   public abstract int getLine(@NotNull MappingEntry paramMappingEntry);
/*  28:    */   
/*  29:    */   public abstract int getColumn(@NotNull MappingEntry paramMappingEntry);
/*  30:    */   
/*  31:    */   public int indexOf(int paramInt1, int paramInt2)
/*  32:    */   {
/*  33: 30 */     int i = 0;
/*  34: 31 */     int j = this.a.size() - 1;
/*  35: 32 */     if ((getLine((MappingEntry)this.a.get(i)) > paramInt1) || (getLine((MappingEntry)this.a.get(j)) < paramInt1)) {
/*  36: 33 */       return -1;
/*  37:    */     }
/*  38: 36 */     while (i <= j)
/*  39:    */     {
/*  40: 37 */       int k = i + j >>> 1;
/*  41: 38 */       MappingEntry localMappingEntry1 = (MappingEntry)this.a.get(k);
/*  42: 39 */       int m = getLine(localMappingEntry1);
/*  43: 40 */       if (paramInt1 == m)
/*  44:    */       {
/*  45: 41 */         if (paramInt2 == getColumn(localMappingEntry1)) {
/*  46: 42 */           return k;
/*  47:    */         }
/*  48:    */         MappingEntry localMappingEntry2;
/*  49: 44 */         if (paramInt2 < getColumn(localMappingEntry1))
/*  50:    */         {
/*  51: 45 */           if (k == 0) {
/*  52: 46 */             return -1;
/*  53:    */           }
/*  54: 49 */           localMappingEntry2 = (MappingEntry)this.a.get(k - 1);
/*  55: 50 */           if (paramInt1 != getLine(localMappingEntry2)) {
/*  56: 51 */             return -1;
/*  57:    */           }
/*  58: 53 */           if (paramInt2 >= getColumn(localMappingEntry2)) {
/*  59: 54 */             return k - 1;
/*  60:    */           }
/*  61: 57 */           j = k - 1;
/*  62:    */         }
/*  63:    */         else
/*  64:    */         {
/*  65: 61 */           localMappingEntry2 = getNextOnTheSameLine(k, false);
/*  66: 62 */           if (localMappingEntry2 == null) {
/*  67: 63 */             return k;
/*  68:    */           }
/*  69: 66 */           i = k + 1;
/*  70:    */         }
/*  71:    */       }
/*  72: 70 */       else if (paramInt1 > m)
/*  73:    */       {
/*  74: 71 */         i = k + 1;
/*  75:    */       }
/*  76:    */       else
/*  77:    */       {
/*  78: 74 */         j = k - 1;
/*  79:    */       }
/*  80:    */     }
/*  81: 78 */     return -1;
/*  82:    */   }
/*  83:    */   
/*  84:    */   @Nullable
/*  85:    */   public MappingEntry get(int paramInt1, int paramInt2)
/*  86:    */   {
/*  87: 84 */     int i = indexOf(paramInt1, paramInt2);
/*  88: 85 */     return i == -1 ? null : (MappingEntry)this.a.get(i);
/*  89:    */   }
/*  90:    */   
/*  91:    */   @Nullable
/*  92:    */   public MappingEntry getNext(int paramInt)
/*  93:    */   {
/*  94: 90 */     return (paramInt >= 0) && (paramInt + 1 < this.a.size()) ? (MappingEntry)this.a.get(paramInt + 1) : null;
/*  95:    */   }
/*  96:    */   
/*  97:    */   @Nullable
/*  98:    */   public MappingEntry getNext(@NotNull MappingEntry paramMappingEntry)
/*  99:    */   {
/* 100: 95 */     if (paramMappingEntry == null) {
/* 101: 95 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/MappingList", "getNext" }));
/* 102:    */     }
/* 103: 95 */     return getNext(Collections.binarySearch(this.a, paramMappingEntry, getComparator()));
/* 104:    */   }
/* 105:    */   
/* 106:    */   @Nullable
/* 107:    */   public MappingEntry getNextOnTheSameLine(int paramInt)
/* 108:    */   {
/* 109:100 */     return getNextOnTheSameLine(paramInt, true);
/* 110:    */   }
/* 111:    */   
/* 112:    */   @Nullable
/* 113:    */   public MappingEntry getNextOnTheSameLine(int paramInt, boolean paramBoolean)
/* 114:    */   {
/* 115:105 */     MappingEntry localMappingEntry1 = getNext(paramInt);
/* 116:106 */     if (localMappingEntry1 == null) {
/* 117:107 */       return null;
/* 118:    */     }
/* 119:110 */     MappingEntry localMappingEntry2 = get(paramInt);
/* 120:111 */     if (getLine(localMappingEntry1) != getLine(localMappingEntry2)) {
/* 121:112 */       return null;
/* 122:    */     }
/* 123:115 */     if (paramBoolean) {
/* 124:117 */       while ((localMappingEntry1 != null) && (getColumn(localMappingEntry1) == getColumn(localMappingEntry2))) {
/* 125:118 */         localMappingEntry1 = getNextOnTheSameLine(++paramInt, false);
/* 126:    */       }
/* 127:    */     }
/* 128:122 */     return localMappingEntry1;
/* 129:    */   }
/* 130:    */   
/* 131:    */   @Nullable
/* 132:    */   public MappingEntry getNextOnTheSameLine(@NotNull MappingEntry paramMappingEntry)
/* 133:    */   {
/* 134:128 */     if (paramMappingEntry == null) {
/* 135:128 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/MappingList", "getNextOnTheSameLine" }));
/* 136:    */     }
/* 137:128 */     MappingEntry localMappingEntry = getNext(paramMappingEntry);
/* 138:129 */     return (localMappingEntry != null) && (getLine(localMappingEntry) == getLine(paramMappingEntry)) ? localMappingEntry : null;
/* 139:    */   }
/* 140:    */   
/* 141:    */   public int getEndOffset(@NotNull MappingEntry paramMappingEntry, int paramInt, @NotNull Document paramDocument)
/* 142:    */   {
/* 143:133 */     if (paramMappingEntry == null) {
/* 144:133 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/sourcemap/MappingList", "getEndOffset" }));
/* 145:    */     }
/* 146:133 */     if (paramDocument == null) {
/* 147:133 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/debugger/sourcemap/MappingList", "getEndOffset" }));
/* 148:    */     }
/* 149:133 */     MappingEntry localMappingEntry = getNextOnTheSameLine(Collections.binarySearch(this.a, paramMappingEntry, getComparator()));
/* 150:134 */     return localMappingEntry == null ? paramDocument.getLineEndOffset(getLine(paramMappingEntry)) : paramInt + getColumn(localMappingEntry);
/* 151:    */   }
/* 152:    */   
/* 153:    */   @NotNull
/* 154:    */   public MappingEntry get(int paramInt)
/* 155:    */   {
/* 156:139 */     MappingEntry tmp13_10 = ((MappingEntry)this.a.get(paramInt));
/* 157:139 */     if (tmp13_10 == null) {
/* 158:139 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/debugger/sourcemap/MappingList", "get" }));
/* 159:    */     }
/* 160:139 */     return tmp13_10;
/* 161:    */   }
/* 162:    */   
/* 163:    */   public boolean processMappingsInLine(int paramInt, @NotNull Processor<MappingEntry> paramProcessor)
/* 164:    */   {
/* 165:144 */     if (paramProcessor == null) {
/* 166:144 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/sourcemap/MappingList", "processMappingsInLine" }));
/* 167:    */     }
/* 168:144 */     int i = 0;
/* 169:145 */     int j = this.a.size() - 1;
/* 170:146 */     while (i <= j)
/* 171:    */     {
/* 172:147 */       int k = i + j >>> 1;
/* 173:148 */       MappingEntry localMappingEntry = (MappingEntry)this.a.get(k);
/* 174:149 */       int m = getLine(localMappingEntry);
/* 175:150 */       if (paramInt == m)
/* 176:    */       {
/* 177:152 */         int n = k;
/* 178:153 */         while ((n > 0) && (getLine((MappingEntry)this.a.get(n - 1)) == paramInt)) {
/* 179:154 */           n--;
/* 180:    */         }
/* 181:    */         do
/* 182:    */         {
/* 183:158 */           if (!paramProcessor.process(this.a.get(n))) {
/* 184:159 */             return true;
/* 185:    */           }
/* 186:162 */           n++;
/* 187:162 */         } while ((n < this.a.size()) && (getLine((MappingEntry)this.a.get(n)) == paramInt));
/* 188:163 */         return true;
/* 189:    */       }
/* 190:165 */       if (paramInt > m) {
/* 191:166 */         i = k + 1;
/* 192:    */       } else {
/* 193:169 */         j = k - 1;
/* 194:    */       }
/* 195:    */     }
/* 196:172 */     return false;
/* 197:    */   }
/* 198:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.sourcemap.MappingList

 * JD-Core Version:    0.7.0.1

 */